<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目提前结清</title>
<jsp:include page="../../import.jsp" flush="true" />
<style type="text/css">
</style>
</head>
<body class="iframeBody">
<div class="Wrapper">
   <form id="prjEaplySettleInfo">
     <div class="fieldset1 tabel_col tabel_col_s clearFix">
         <div class="caption">
			<span class="title">项目提前结清信息 </span>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">项目名称</div>
		   <div class="field">
              <span id="fncPrjNm" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">项目编号</div>
		   <div class="field">
              <span id="fncPrjIdStr" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">创建时间</div>
		   <div class="field">
              <span id="prjCrtTm" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">融资机构</div>
		   <div class="field">
              <span id="fncInsNm" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">融资方案</div>
		   <div class="field">
              <span id="fncScmNm" ></span>
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">提前结清期次</div>
		   <div class="field">
              <select name="esPd" id="esPd" data-value="" onchange= "changeEsPdValue()" validate="{required:true}">
                   <c:forEach items="${esPdList}" varStatus="i" var="item" >  
					  <option value="${item}">${item}</option>
				   </c:forEach>
              </select> 
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">预计结清时间</div>
		   <div class="field">
		     <input name="payTm" id="payTm" type="text" class="ui-datepicker" value="" validate="{required:true}">
		   </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">机构收款账户</div>
		   <div class="field">
		      <input name="recvAcc" id="recvAcc" type="text" class="ui-textbox" value="" validate="{required:true}">
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">我司付款账户</div>
		   <div class="field">
		     <input name="payAcc" id="payAcc" type="text" class="ui-textbox" value="" validate="{required:true}">
           </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">应还本金</div>
		   <div class="field">
		     <input name="capital" id="capital" type="text" class="ui-textbox" value="" onchange="updateOtherChar()"  validate="{required:true}">
		   </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">应还利息</div>
		   <div class="field">
		     <input name="interest" id="interest" type="text" class="ui-textbox" onchange="updateInterest(this.value)"  value="" validate="{required:true}">
		   </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">其他费用</div>
		   <div class="field">
		     <input name="otherChar" id="otherChar" type="text" class="ui-textbox" onchange="updateOtherChar()" value="" validate="{required:true}">
		   </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label">结清费用</div>
		   <div class="field">
		     <input name="setlleChar" id="setlleChar" type="text" class="ui-textbox"  onchange="updateSetlleChar()" value="" validate="{required:true}">
		   </div>
		</div>
			<div class="fieldBox col_33">
		   <div class="label">合计</div>
		   <div class="field">
		     <input name="allChar" id="allChar" type="text" class="ui-textbox" value="" validate="{required:true}">
		   </div>
		</div>
		<div class="fieldBox col_33">
		   <div class="label"></div>
		   <div class="field">
		   </div>
		</div>
		<div class="fieldBox col_100" id="fileModify">
			<div class="label">资料</div>
			<div class="field">
               	<jsp:include page="../../system/sysUlFilesRec/sysUlFileRecList.jsp" flush="true" >
                  	<jsp:param name="pkId" value="${lgcId }"/>
                  	<jsp:param name="tabNm" value="CST_BSC_INFO"/>
                </jsp:include>
           	</div>
		</div>
		<div class="fieldBox col_100">
			<div class="label">资料上传</div>
			<div class="field">
                <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload2.jsp" flush="true" >
                  	<jsp:param name="filePath" value="customer"/>
                </jsp:include>
			</div>
	    </div> 
	    <div class="fieldBox col_100">
			<div class="label">备注</div>
			<div class="field" style="width:100%" >
			     <textarea name="rmrk" id="rmrk" rows="4" class="l-textarea" style="width:100%"></textarea>
		    </div>
		</div>
	</div><br/>
	<div class="btnsBox" align="center">
		<span id="mrgn_deduct_info_add_btn_id"
			class="sq-button sq-button-round" onclick="save();">保存
		</span>
		<span id="mrgn_deduct_info_btn_id"
			class="sq-button sq-button-round" onclick="closeWind();">关闭
		</span>
	 </div>
	<div class="fieldset1 tabel_col_s clearFix" > <!-- fieldset1 tabel_col tabel_col_s clearFix -->
	   <div class="caption">
		   <span class="title" >可分解还款列表 </span>
	   </div>
	  <div id="prjPayTbligergrid" class="sq-grid"></div>
	</div>
	<!-- hidden -->
	<div class="fieldBox col_100" style="display:none;">
	  <div class="field">
		<input name="esPdInterest" id="esPdInterest" type="text" class="ui-textbox"  value="" validate="{required:true}">
	    <input name="prjid" id="prjid" type="text" class="ui-textbox" value="${prjLgcId}"  >
	    <input name="lgcId" id="lgcId" type="text" class="ui-textbox" value="${lgcId}"  >
	    <input name="fncInsId" id="fncInsId" type="text" class="ui-textbox" value="${fncInsId}"  >
	  </div>
	</div>
   </form>
</div>

<script type="text/javascript">
   var prjPayInfoList=[];
   var PayInfoListIs=1;
   $(function() {
	 initRecvList();
	 initPayList();
	 $("#prjEaplySettleInfo").ligerForm({
	     validate: true
     });
	  initData();
	 });
   
   function initData(){
	  var lgcId=$("#lgcId").val();
	  var prjLgcId=$("#prjid").val();
	  if(!prjLgcId&&!lgcId)  return;
	  var data=new Object();
	  data["lgcId"]=lgcId;
	  data["prjLgcId"]=prjLgcId;
	  var _url = '<%=path%>/rfbase/fncprjeaplysettle/prjEaplySettlePageinit.do';
      if(lgcId!=""&&lgcId!=null){
    	  _url = '<%=path%>/rfbase/fncprjeaplysettle/prjEaplySettleUpdatePageinit.do';
	  }
	   AjaxUtils.ajaxPost(_url, data, callback);
	}
		
	  //新增回调
   function callback(msg){
	  if(msg.success == 1){
		  setData(msg.data);//设置数据
	  }else{
		  UIUtils.alertError(msg.info);
	  }
   }
		
	//设置页面数据
   function setData(data){
		var lgcId=$("#lgcId").val();
	    var settlePrjDetail=data["settlePrjDetail"];
	    prjPayInfoList=data["FncPrjPayTbInfoList"];
	    var fncPrjEaplySettle=settlePrjDetail.fncPrjEaplySettle;
	    $("#fncPrjIdStr").html(settlePrjDetail.fncPrjIdStr);
	    $("#fncPrjNm").html(settlePrjDetail.fncPrjNm);   
	    $("#prjCrtTm").html(renderDateChange(settlePrjDetail.crtTm));
		$("#fncInsNm").html(settlePrjDetail.fncInsNm);
		$("#fncScmNm").html(settlePrjDetail.fncScmNm);
		if(prjPayInfoList==null||prjPayInfoList.length==0){
	    	UIUtils.alertError("该项目没有还款计划表！");
	    	PayInfoListIs=0;
	    	return false; 
	    }
		var form = new liger.get("prjEaplySettleInfo");
		form.setData({
			esPd : fncPrjEaplySettle.esPd,
			interest : fncPrjEaplySettle.interest,
			capital : fncPrjEaplySettle.capital,
			rmrk : fncPrjEaplySettle.rmrk
		});
		
		//期次
		var esPd=fncPrjEaplySettle.esPd;
		//修改赋值
		if(lgcId!=""&&lgcId!=null){
			
			form.setData({
				recvAcc : fncPrjEaplySettle.recvAcc,
				payAcc : fncPrjEaplySettle.payAcc,
				otherChar : fncPrjEaplySettle.otherChar,
				payTm : fncPrjEaplySettle.payTm,
				interest : fncPrjEaplySettle.interest,
				setlleChar : fncPrjEaplySettle.setlleChar,
				allChar : fncPrjEaplySettle.allChar
			});
			//编辑利息
			var interestVale=fncPrjEaplySettle.interest;
			var interestnum=0;
			for(var i=0;i<prjPayInfoList.length;i++){
				if(i<esPd-1){
					interestnum =accAdd(interestnum,prjPayInfoList[i].arInterest);
			    }
				else if(i==esPd-1)
	            {
					prjPayInfoList[i].interestEp=Subtr(interestVale,interestnum);
					$("#esPdInterest").val(prjPayInfoList[i].interestEp);
				}else{
					prjPayInfoList[i].interestEp=0;
				}
			 }
		}else{
			var interestnum=0;
			for(var i=0;i<prjPayInfoList.length;i++){
				if(i<esPd-1){
					interestnum =accAdd(interestnum,prjPayInfoList[i].arInterest);
				}else if(i<esPd){
					interestnum =accAdd(interestnum,prjPayInfoList[i].arInterest);
					$("#esPdInterest").val(prjPayInfoList[i].arInterest);
				}else{
					prjPayInfoList[i].interestEp=0;
				}
			 }
			$("#otherChar").val(0);
			$("#setlleChar").val(0);
			$("#interest").val(interestnum.toFixed(2));
			$("#allChar").val(accAdd(fncPrjEaplySettle.capital,interestnum));
		}
		f_showprjPayTbInfo(prjPayInfoList);
  };

  function f_getDetailData(listChange)
  {
      var data = { Rows: [] };
      for (var i = 0; i < listChange.length; i++)
      {
         data.Rows.push(listChange[i]);
      }
      return data;
  }
 
   //显示还款List
    function f_showprjPayTbInfo(prjPayInfoList)
    { 
    	prjPayInfoList[prjPayInfoList.length-1].srplsCapitalEp=0;
		for(var i=0;i<prjPayInfoList.length-1;i++){
			prjPayInfoList[prjPayInfoList.length-2-i].srplsCapitalEp=accAdd(prjPayInfoList[prjPayInfoList.length-1-i].srplsCapitalEp,prjPayInfoList[prjPayInfoList.length-1-i].arCapital);
		}
	    $("#prjPayTbligergrid").ligerGrid({
	        columns: [
	            { display: '支付表详细逻辑编号',name: "id", width: 150,hide: true}, 
	            { display: '期次', name: 'payPdEp', width: 150 },
	            { display: '支付时间', name: 'payTmEp', width: 150,render:renderDate},
	            { display: '租金', name: 'rentalEp', width: 100, render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	      enabledSort:true}, 
	            { display: '本金', name: 'capitalEp', width: 100, render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	      enabledSort:true}, 
	            { display: '利息', name: 'interestEp', width: 100, render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	      enabledSort:true}, 
	            { display: '已还租金', name: 'rentaledEp', width: 200, render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	      enabledSort:true}, 
	            { display: '剩余本金', name: 'srplsCapitalEp', width: 100, render: function (rowdata, rowindex, value, column) { 
	            	var money =moneyChange(value);
                    return money;
            		},
        	      enabledSort:true}
	        ],
	        usePager:false,
	        data:f_getDetailData(prjPayInfoList),
	        width:'100%',
	        height:'400'
	    });
    }
   
    function initRecvList(){ 
   	   var instid = $("#fncInsId").val();
   	   $("#recvAcc").ligerComboBox({
             columns: [
 	                { header: '开户行号', name: 'banAccNum', width: 140}, 
 	                { header: '开户行名', name: 'banAccNm', width: 140}, 
 	                { header: '账户名称', name: 'accNm', width: 120},
 	                { header: '账号', name: 'accNum', width: 120}
 	               ],
 	            url:'<%=path%>/rfbase/fncprjeaplysettle/initRecvList.do?insId='+instid,
 	            ajaxType :'GET',
 	            width: 200, slide: false,
 	            selectBoxWidth: 680, selectBoxHeight: 240,
 	            valueField:'id',textField: 'accNum'     
 	       });
      }
     function initPayList(){
   	   var instid = $("#fncInsId").val();
   	   $("#payAcc").ligerComboBox({
             columns: [
 	                { header: '开户行号', name: 'bkId', width: 140}, 
 	                { header: '开户行名', name: 'bkNm', width: 140}, 
 	                { header: '账户名称', name: 'accNm', width: 120},
 	                { header: '账号', name: 'accNo', width: 120}
 	               ],
 	            url:'<%=path%>/rfbase/fncprjeaplysettle/initPayList.do?insId='+instid,
 	            ajaxType :'GET',
 	            width: 200, slide: false,
 	            selectBoxWidth: 680, selectBoxHeight: 240,
 	            valueField:'id',textField: 'accNo'
 	       });
     }
     
   function  changeEsPdValue(){
	  var prjLgcId=$("#prjid").val();
	  if(!prjLgcId)  return;
	  var data=new Object();
	  data["prjLgcId"]=prjLgcId;
	  var _url = '<%=path%>/rfbase/fncprjeaplysettle/getPayListInfo.do';
	  AjaxUtils.ajaxPost(_url, data, callbackChangeEsPd); 
   }
  
   //新增回调
   function callbackChangeEsPd(msg){
	  if(msg.success == 1){
		  prjPayInfoList=msg.data;//设置数据
		  var esPd=$("#esPd").val();
	 	  //编辑利息为0
	 	  var interestnum=0;
		  for(var i=0;i<prjPayInfoList.length;i++){
			if(prjPayInfoList[i].payPdEp<esPd){
				interestnum =accAdd(interestnum,prjPayInfoList[i].arInterest);
		    }else if(prjPayInfoList[i].payPdEp==esPd){
		    	interestnum =accAdd(interestnum,prjPayInfoList[i].arInterest);
				$("#esPdInterest").val(prjPayInfoList[i].arInterest);
		    }
			else{
				prjPayInfoList[i].interestEp=0;
			}
		  } 
	 	  $("#interest").val(interestnum.toFixed(2));
	 	  f_showprjPayTbInfo(prjPayInfoList);
	 	  updateOtherChar();
	  }else{
		  UIUtils.alertError("数据查询不成功");
	  }
   }
	
   function updateInterest(interestVale){
	   var esPd=$("#esPd").val();
	   //编辑利息为0
	   var interestnum=0;
	   for(var i=0;i<prjPayInfoList.length;i++){
			if(prjPayInfoList[i].payPdEp<esPd){
				interestnum =accAdd(interestnum,prjPayInfoList[i].arInterest);
		    }
			else if(prjPayInfoList[i].payPdEp==esPd)
            {
				 if(interestVale-interestnum<0){
					   var interestsum=accAdd(interestnum,prjPayInfoList[i].arInterest);
					   $("#interest").val(interestsum.toFixed(2));
					   UIUtils.alertError("当前还款期次的利息小于零，请输入大于"+interestnum.toFixed(2) +"！");
					   return ;
					}
				prjPayInfoList[i].interestEp=Subtr(interestVale,interestnum);
				$("#esPdInterest").val(prjPayInfoList[i].interestEp);
			}else{
				prjPayInfoList[i].interestEp=0;
			}
		} 
	   f_showprjPayTbInfo(prjPayInfoList);
	   updateOtherChar();
   }
   
   function updateSetlleChar(){
	   updateOtherChar();
   }
     
   function updateOtherChar(){
	  
	  var capital=$("#capital").val();
	  var interest=$("#interest").val();
	  var otherChar=$("#otherChar").val();
	  var setlleChar=$("#setlleChar").val();
	  if(/[^0-9\.]/.test(capital)&&/[^0-9\.]/.test(interest)&&/[^0-9\.]/.test(otherChar)&&/[^0-9\.]/.test(setlleChar)){
		  UIUtils.alertError("请输入有效数字！");
	      return false;
	  }
	  var allChar=parseFloat(capital)+parseFloat(interest)+parseFloat(otherChar)+parseFloat(setlleChar);
	  document.getElementById("allChar").value=allChar;
   }
     
  //提交
 function save() {
    if(PayInfoListIs==0){
	    UIUtils.alertError("该项目没有还款计划表,无法提交！");
	    return false; 
	 }
    	
     //校验
     if($("#payTm").val()==null||$("#payTm").val()==""){
    	 UIUtils.alertError("“预计结清时间”未填写,无法提交！");
	    	return false; 
     }
     if(($("#recvAcc").val()==null||$("#recvAcc").val()=="")&&($("#payAcc").val()==null||$("#payAcc").val()=="")){
    	 UIUtils.alertError("“机构收款账户”与“我司付款账户”同时未填写,无法提交！");
	    	return false; 
     }
     if($("#capital").val()==null||$("#capital").val()==""){
    	 UIUtils.alertError("“应还本金”未填写,无法提交！");
	    	return false; 
     }
     if($("#interest").val()==null||$("#interest").val()==""){
    	 UIUtils.alertError("“应还利息”未填写,无法提交！");
	    	return false; 
     }
     if($("#otherChar").val()==null||$("#otherChar").val()==""){
    	 UIUtils.alertError("“其他费用”未填写,无法提交！");
	    	return false; 
     }
     if($("#setlleChar").val()==null||$("#setlleChar").val()==""){
    	 UIUtils.alertError("“结清费用”未填写,无法提交！");
	    	return false; 
     }
     if($("#allChar").val()==null||$("#allChar").val()==""){
    	 UIUtils.alertError("“合计”未填写,无法提交！");
	    	return false; 
     }
      var ligerForm = liger.get("prjEaplySettleInfo");
      var data = ligerForm.getData();
      data["prjid"]=$("#prjid").val();
      data["lgcId"]=$("#lgcId").val();
      
    //获取附件上传的信息
      var docArray = getUploadResultParams();
      data["docArray"] = JSON.stringify(docArray);
      
     //编辑URL
      var url='<%=path%>/rfbase/fncprjeaplysettle/updateEaplySettleInfo.do';
      if( data["lgcId"]==null|| data["lgcId"]==''){
    	  //添加URL
    	  var url='<%=path%>/rfbase/fncprjeaplysettle/addEaplySettleInfo.do';
      }
      
      $.ajax({
   		type: 'post',
   		dataType:'json', 
   		data:data,
   		url: url,
   		beforeSend: function(){
   	       wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
   	     },
   		success:function(msg){
   			 wait_dialog.close();
   			 var e=msg.success;
   			 if(msg.success == 1){
   				var lgcId=$("#lgcId").val();
   				if(lgcId==null||lgcId==''){
   					$("#lgcId").val(msg.data);
   					startEarlyPayFlow(); 
				 }else{
					 $.ligerDialog.success(msg.info);
				 }
   			 }else{
   				 $.ligerDialog.error(msg.info);
   			 }
   		}
     });
   }
    
  //发起审核流程
  function startEarlyPayFlow(){
     var _id=$("#lgcId").val();
     if(!_id){
		   UIUtils.alertError("请先保存再发起流程！");
		   return ;
		}
	 var modelTyp ="R011";//流程业务分类-再融资提前还款流程
	 if(StringUtils.isEmpty(modelTyp)){
		console.log("modelTyp is null");
		return;
	 }
     var flowDialog = $.ligerDialog.SQopen({
         url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp='+modelTyp,
         width: 700,
         height:400,
         title : '请选择要发起的流程',allowClose:false,
         buttons: [{
 	                text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
 	                onclick: function (item, Dialog) {
 	                    if (Dialog.onOk) Dialog.onOk();
 	                }
 	            }, {
 	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
 	                onclick: function (item, Dialog) {
 	                    if (Dialog.onCancel) Dialog.onCancel();
 	                }
 	            }
 	        ],
         onClose: function () {
         	var json = flowDialog._DATA;
         	console.log(json);
         	if(!json){
         		closeWind();
             	return;
         	}
         	var wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
     		$.ajax({
         		type: 'post',
         		dataType:'json',
         		data:{
         			id:_id,
         			procDefKey:json.procDefKey,
         			procDefId:json.procDefId,
         			procNo:json.procNo
         		},
         		url: '<%=path%>/rfbase/fncprjeaplysettle/addPrjEaplySettleFlowStart.do',
         		success:function(msg){
         			wait_dialog.close();
         			 if(msg.success == 1){
       					 UIUtils.alertSuccessHold1(msg.info);
       					 closeWind();
 	           		 }else{
 	          			 UIUtils.alertErrorHold1(msg.info);
 	           		}
         		}
         	});
         }
     });
   }	  
    
  //关闭页面
  function closeWind(){
	var selectedTabId = parent.mainApp.parentTab.selectedTabId;
	var lastTab = parent.tabItems[0];
	parent.mainApp.parentTab.reload(lastTab.tabid);
	parent.mainApp.parentTab.removeTabItem(selectedTabId);
	parent.grid.reload();
  }

 //格式化时间
 function renderDateChange(value){
	var dateStr = "";
	if(null != value &&  ""!= value){
		var date = new Date(value);
		dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
	}
	return dateStr;
 } 
 
//格式化时间
 function renderDate(rowdata, index, value){
	var dateStr = "";
	if(null != value){
		var date = new Date(value);
		dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
	}
	return dateStr;
 }
 
//格式化金额
 function moneyChange(value) { 
		var h = '';
			if(value&&value!="null"){
		    h+=fmoney(value, 2);
			}else{
			h+="0.00";
			}
         return h;
		}
 
 //格式化金额
 function fmoney(s, n)   
	{   
	   n = n > 0 && n <= 20 ? n : 2;   
	   s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";   
	   var l = s.split(".")[0].split("").reverse(),   
	   r = s.split(".")[1];   
	   t = "";   
	   for(i = 0; i < l.length; i ++ )   
	   {   
	      t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");   
	   }   
	   return t.split("").reverse().join("") + "." + r;   
	} 
 
 //js 加法计算  
 //调用：accAdd(arg1,arg2)  
 //返回值：arg1加arg2的精确结果   
 function accAdd(arg1,arg2){   
   var r1,r2,m;   
   try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}   
   try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}   
   m=Math.pow(10,Math.max(r1,r2))   
   //return ((arg1*m+arg2*m)/m).toFixed(2);   
   return ((arg1*m+arg2*m)/m); 
 }   
 
 //js 减法计算  
 //调用：Subtr(arg1,arg2)  
 //返回值：arg1减arg2的精确结果   
 function Subtr(arg1,arg2){  
      var r1,r2,m,n;  
      try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}  
      try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}  
      m=Math.pow(10,Math.max(r1,r2));  
      //last modify by deeka  
      //动态控制精度长度  
      n=(r1>=r2)?r1:r2;  
      return ((arg1*m-arg2*m)/m).toFixed(2);  
 }
 
</script>

</body>
</html>
